package com.asset.dispoal.file.agreementCaseData.service.commom;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.asset.dispoal.file.agreementCaseData.domain.dto.BsDataDetailExportTemplate;
import com.asset.dispoal.file.agreementCaseData.service.excelListener.DataDetailExcelListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.util.Map;

/**
 * @author qr
 * @date 2022/4/6$
 */
@Component
public class UploadExcelCommand implements BaseCommand<Map<String, String>, Result> {


    @Autowired
    FileExcelDataSaveCommand fileExcelDataSaveCommand;

    @Autowired
    Environment environment;

    @Override
    public Result execute(Map<String, String> map) {
        String filePath = environment.getProperty("file.evidence.url") + "/" + map.get("filePath");
        String assetInstBatchId = map.get("assetInstBatchId");
        ExcelReaderBuilder read = EasyExcel.read(filePath, BsDataDetailExportTemplate.class, new DataDetailExcelListener(fileExcelDataSaveCommand, assetInstBatchId));
        read.sheet().doRead();
        return Result.ok();
    }
}
